package com.gjy.concurrency.clazz;

import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-05-18 10:59:05
 */
@Slf4j
public class CallableTest {

    @Test
    public void test2() {
    }

    @Test
    public void test1() throws ExecutionException, InterruptedException {
        Callable<String> c1 = new Call1();

        FutureTask<String> ft = new FutureTask<>(c1);
        new Thread(ft).start();

        String s = ft.get();
        log.info("s = {}", s);
    }

    private static final class Call1 implements Callable<String> {

        @Override
        public String call() throws Exception {
            DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
            return LocalDateTime.now().format(pattern);
        }
    }
}
